home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
demos
/
GL
/
curve
/
spaced.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
7KB
|
201 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/******************************************************************************
Spaced: The Three-D Space Editor
These routines provide a rather bizarre but surprisingly intuitive way
to move a point in three dimensions using a two dimensional mouse.
It works by projecting a set of axes into two-d screen space, then
determining where within those projected axes the mouse is. The
projected axes will divide the screen into six pie pieces. If for
example, the mouse is between the projected versions of the
positive X and positive Z axis, the point being moved will follow
the mouse with its motion constrained to the X-Z plane.
To make things even simpler, holding the shift key will constrain
motion to one axis, instead of a plane. The shift key may be
pressed after unconstrained motion has begun. Motion is contrained
to the axis closest to the cursor. Similary, the alt key will constrain
motion to a plane.
It sounds funny, but it works really well. Try the example program to see for
yourself. Just type "spaced". The window shows a view volume filled
with control points. Use the left mouse button to select and move
one of the control points. Use the middle mouse button to rotate
the view volume. Try using the shift key to constrain motion.
*****************************
HOOKING IT UP TO YOUR PROGRAM
*****************************
Using Spaced from a program is very simple. You only need to pass it
a matrix, a point, and some limits.
Once you know what point you will be moving, make a call to
void start_spaced(void);
Everytime you want to update that point's position, call
int spaced(Matrix M, Coord origin[3], Coord limit[3][2]);
M contains the matrix that gets your point from world space to
screen space. In single matrix mode, this is simply the matrix on
the top of the matrix stack at the time you would normally display
your object (use getmatrix()). In double matrix
mode, this is the matrix which result from multiplying the viewing
matrix by the projection matrix.
origin is the coordinates of the point that will be moved. If you are
moving an object, this is the origin of your object, in world
coordinates, or whatever other convienient thing you may want to do with it.
limit specifies the bounding box, in 3D world coordinates, that you
want motion constrained to. Your bounding box can be really big, but
you must specify something. Also, be certain that the origin
initially is within the bounding box that you specify, otherwise
Spaced will freak out.
The format is limit[x=0, y=1, z=2][lo=0,hi=1]
For example, if you want motion to stay within a -1.0 to 1.0 cube, say
Coord limit[3][2] =
{ { -1.0, 1.0},
{ -1.0, 1.0},
{ -1.0, 1.0}
};
the integer it returns describes which axis or plane the user is constraining
motion to. The value will be SP_NONE, SP_X_AXIS, ..., SP_XY_PLANE, etc.
Simply set up your event processing to repeatedly call spaced() for as
long as you want to modify the contents of origin.
When motion of your point is completed to your satisfaction, call
end_spaced();
At any time, call
void set_spaced(
int col_thresh,
int const_thresh,
Device line1,
Device line2,
Device plane1,
Device plane2);
to change Spaced's default setup values. If you want to permanently change
the defaults, edit the #define's at the bottom of this file. The meaning
of these arguments is desribed next.
****************
SETUP PARAMETERS
****************
The colinearity threshhold specifies, in pixels, when to start ignoring
axes. In some views of your axes, you will see that two axes will come
close to being colinear. When two axes come within the threshhold
pixels of being colinear, the shorter of the two will be ignored.
Also, axes may become very small if you are looking right down them.
The colinear threshold will cause small axes to be ignored, since a small
axis may come within col_thresh pixels of being colinear with
the other axes.
The moral: If things start acting wierd, play with the colinear
threshold.
The constrint threshhold specifies how many pixels away from the initial
position the mouse should be before we start doing constrained motion.
This insures that the point is moved where the user really wanted it to.
Increase it to be more sure; decrease to have motion start happening
more quickly.
By default, either shift key constrains motion to a line, and either alt key
constrains motion to a plane. However, you can use any button device(s)
you like. Notice that there are two devices for each type of
constraining to allow for duplicate keyboard keys (like left and right
shift keys). If you want to use only one device, use it for both
parameters. To reset any of the parameters to their default values,
use SP_DEFAULT as an argument.
*****
HINTS
*****
Typically, you will want to draw the axes through the point of motion
within you bounding box. Without them, it is very hard to see what
is going on.
You may want to depth cue your axes or even your objects to give the
user a little better feel for what is happening.
Use the return value for more user hints, such as displaying the plane
that motion is contrained to in a different color.
***************************
OTHER BUGS, COMMENTS, SUGGESTIONS
***************************
Please send them to:
Howard Look
howardl@sgi.com
335-1780
Version 1.1: April 22, 1990
*************************************************************************/
#define SP_COLINEAR_THRESHOLD 20
#define SP_CONSTRAINT_THRESHOLD 10
#define SP_LINE_BUTTON1 LEFTSHIFTKEY
#define SP_LINE_BUTTON2 RIGHTSHIFTKEY
#define SP_PLANE_BUTTON1 LEFTALTKEY
#define SP_PLANE_BUTTON2 RIGHTALTKEY
#define SP_DEFAULT -1
#define SP_NONE -1
#define SP_X_AXIS 1
#define SP_Y_AXIS 2
#define SP_Z_AXIS 3
#define SP_XY_PLANE 4
#define SP_XZ_PLANE 5
#define SP_YZ_PLANE 6
/* prototypes for your files */
extern void start_spaced();
extern int spaced(
Matrix,
Coord origin[3],
Coord limit[3][2]);
extern void end_spaced(void);
extern void set_spaced(
int col_thresh,
int const_thresh,
Device line1,
Device line2,
Device plane1,
Device plane2);